package com.myk.game.heroscuffle.signs;

import com.myk.game.heroscuffle.game.Hero;
import com.myk.game.heroscuffle.game.HeroSchool;
import com.myk.game.heroscuffle.game.Sign;
import com.myk.game.heroscuffle.game.Skill;

/**
 * 持续时间类标记
 */
public abstract class TimeSign extends Sign {

    public final int SIGN_TIME;
    public int remainingTime;

    public TimeSign(String SIGN_NAME, int SIGN_TIME) {
        super(SIGN_NAME);
        this.SIGN_TIME = SIGN_TIME;
    }

    @Override
    public String getObviousName() {
        return "/" + SIGN_NAME + "r:" + remainingTime + "/";
    }

    @Override
    protected final void paste(Hero hostHero) {
        this.hostHero = hostHero;
        this.game = hostHero.game;
        boolean has = false;
        for (Sign sign : hostHero.SIGNS) {
            if (sign.getClass() == this.getClass()) { //这类标记如果原来已经存在，新增时只更新冷却时间
                game.ui.printMsg(hostHero.getObviousName() + "更新" + SIGN_NAME + "标记。");
                game.ui.sleepShortly();
                ((TimeSign) sign).remainingTime = SIGN_TIME;
                has = true;
            }
        }
        if (!has) {
            game.ui.printMsg(hostHero.getObviousName() + "添加" + SIGN_NAME + "标记。");
            game.ui.sleepShortly();
            remainingTime = SIGN_TIME;
            hostHero.SIGNS.add(this);
        }
    }

    @Override
    protected final void update() {
        if (remainingTime > 0) { //结算持续时间
            remainingTime -= 1;
        }
        onUpdate();
        if (remainingTime == 0) { //时间到了自动移除标记
            hostHero.removeSign(this.getClass());
        }
    }

    protected void onUpdate() {
    }

}
